<template>
    <div class="feixing_container" v-loading="loading" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0)">
        <Rank :subForm="subForm" @getDataList="getDataList" />
        <Table :subForm="subForm" :tableData="tableData" :total="total" @getDataList="getDataList" />
    </div>
</template>

<script>
import Rank from "./model/Rank";
import Table from "./model/Table";
export default {
    components: {
        Rank,
        Table
    },
    name: "",
    data() {
        return {
            loading: false,
            subForm: {
                creator_name: "",
                industry:[],
                follower_cnt:[],
                age: {
                    name: "",
                    range: [],
                },
                sex: {
                    name: "",
                    range: [],
                },
                is_quickly_response:0,
                is_active_creator:0,
                is_high_sample_dispatch_rate:0,
                region:"ID",
                field: "",
                order: "",
                page: 1,
                limit: 20,
            },
            total: 0,
            tableData: [],
        };
    },
    created() {
        this.getDataList(1);
    },
    beforeDestroy() {},
    methods: {
        //获取列表
        async getDataList() {
            this.loading = true;
            const { data: res } = await this.$http.post(
                "privateorder/Indonesian/bloggerList",
                this.subForm
            );
            if (res.code !== 200) {
                this.loading = false;
                this.$message.error(res.msg);
                return;
            } else {
                this.sql = res.data.sql
                for (let i in res.data.list) {
                    let ageArr = [];
                    ageArr.push({
                        name: "18_24岁",
                        value: (
                            Number(res.data.list[i].crowd_ages_18_24) * 100
                        ).toFixed(1),
                    });
                    ageArr.push({
                        name: "25_34岁",
                        value: (
                            Number(res.data.list[i].crowd_ages_25_34) * 100
                        ).toFixed(1),
                    });
                    ageArr.push({
                        name: "大于35岁",
                        value: (
                            Number(res.data.list[i].crowd_ages_35_more) * 100
                        ).toFixed(1),
                    });
                    
                    res.data.list[i].ageArr = ageArr.sort(
                        this.sortFun("value")
                    );
                }

                this.loading = false;
                this.tableData = res.data.list;
                this.total = res.data.count;
            }
        },

        sortFun(property) {
            return function (a, b) {
                var value1 = a[property];
                var value2 = b[property];
                return value2 - value1; //升序排序
            };
        },
       
    },
};
</script>


<style scoped>

</style>


